package lesson01;

import java.net.DatagramPacket;
import java.net.DatagramSocket;

/**
 * @Auther: xiaofei
 * @Date: 2021/6/28 - 06 - 28 - 16:11
 * @Description: lesson01
 * @version: 1.0
 */
public class UDPServerDemo01 {
    //这是一个main方法，是程序的入口：
    public static void main(String[] args) throws Exception {
        // 开放端口
        DatagramSocket socket = new DatagramSocket(9090);
        // 接收数据包
        byte[] buffer = new byte[1024];
        DatagramPacket packet = new DatagramPacket(buffer, 0, buffer.length);
        socket.receive(packet);
        System.out.println(packet.getAddress().getHostName());
        System.out.println(new String(packet.getData(),0,packet.getLength()));

        // 关闭连接
        socket.close();
    }
}
